package mainwindow;

import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.JInternalFrame;
import javax.swing.*;
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.KeyStroke;


public class Mainwindow extends JFrame 
{
	
// Important -------------------------------------------------------------
	private JMenuBar menubar = new JMenuBar();
	private JToolBar toolbar = new JToolBar("Tools");
	private JMenu file = new JMenu("File");
	private JMenu helpmenu = new JMenu("Help");
    private JDesktopPane desktop;
	
// Actions ----------------------------------------------------------------
	private Action novo = new NewAction();
	private Action save = new SaveAction();
	private Action open = new OpenAction();
	private Action close = new ExitAction();
	private Action about = new AboutWindow();

// Other variables --------------------------------------------------------
	/**
	 * Make the big window be indented 50 pixels from each edge
	 * of the screen.
	 */
    int inset = 50;

	
	public Mainwindow(String name, int x, int y) 
	{
		super("Java Front End for Gnuplot");
		
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setBounds(inset, inset,
                screenSize.width  - inset*2,
                screenSize.height - inset*2);
		
		Container interno = this.getContentPane();
		this.makeMenu();
		this.makeTools();
		this.makeGUI(interno);
	}

	private void makeMenu() 
	{
		// File menu
		this.file.add(new JMenuItem(this.novo));
		this.file.add(new JMenuItem(this.save));
		this.file.add(new JMenuItem(this.open));
		file.addSeparator();
		this.file.add(new JMenuItem(this.close));
		this.menubar.add(this.file);
		
		// Help menu
		this.helpmenu.add(new JMenuItem(this.about));
		this.menubar.add(this.helpmenu);
		
		this.setJMenuBar(this.menubar);
	}

	private void makeTools() 
	{
		this.toolbar.add(this.novo);
		this.toolbar.add(this.open);
		this.toolbar.add(this.save);
	}

	private void makeGUI(Container interno) 
	{
		interno.setLayout(new BorderLayout());
		interno.add(this.toolbar, BorderLayout.NORTH);
		
		desktop = new JDesktopPane();
		createFrame("plot");
		createFrame("data base");
		getContentPane().add(desktop);
	    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
//		interno.add(desktop, BorderLayout.SOUTH);
	}
	
	protected void createFrame(String tipo) 
	{
	    InternalWindow frame = new InternalWindow(tipo);
	    frame.setVisible(true);
	    desktop.add(frame);
	    try 
	    {
	        frame.setSelected(true);
	    }
	    catch (java.beans.PropertyVetoException e) {}
	}
	
}